import json

import requests

from common.config import cmslogin, getconf


class DataAccess:
    def getProjectList(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/dict/getProjectList"
        token = cmslogin(env)
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        data={"projectCode":"terminal_mall","appId":"com.rongyi.custom","appType":"1","appVersion":"2.32.16","pageCode":"p_1006","pageName":"自动化","dataStatus":"","creatorName":"郝瑞敏","sortFields":"","sortType":"","current":1,"size":100}
        r=requests.post(url=url,data=json.dumps(data),headers=header)
        print('数据接入-项目列表')
        return r.json()

    def getProjectSelect(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/dict/getProjectSelect"
        token = cmslogin(env)
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        data={"projectName":"terminal"}
        r=requests.post(url,data=json.dumps(data),headers=header)
        print('数据接入-控件项目列表')
        return r.json()

    def getAppSelect(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/dict/getAppSelect"
        token = cmslogin(env)
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        data={"appName":"商场","projectCode":"terminal_mall"}
        r=requests.post(url,data=json.dumps(data),headers=header)
        print('数据接入-控件应用列表')
        return r.json()

    def getAppVerSelect(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/dict/getAppVerSelect"
        token = cmslogin(env)
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        data={"appId":"com.rongyi.custom","projectCode":"terminal_mall"}
        r=requests.post(url,data=json.dumps(data),headers=header)
        print('数据接入-控件应用版本列表')
        return r.json()

    def getPageSelect(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/dict/getPageSelect"
        token = cmslogin(env)
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        data={"projectCode":"terminal_mall","appId":"com.rongyi.custom","appVersion":"2.32.16"}
        r=requests.post(url,data=json.dumps(data),headers=header)
        print('数据接入-控件页面列表')
        return r.json()

    def editPage(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/dict/editPage"
        token = cmslogin(env)
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        data={"id":49,"name":"自动化1","pageName":"自动化1"}
        r=requests.post(url,data=json.dumps(data),headers=header)
        print('编辑页面名称',r.json())
        return r.json()

    def editPage_null(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/dict/editPage"
        token = cmslogin(env)
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        data={"id":50,"name":"","pageName":""}
        r=requests.post(url,data=json.dumps(data),headers=header)
        print('编辑页面名称测试为空',r.json())
        return r.json()

    def getProjectDetail(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/dict/getProjectDetail/31/48"
        token = cmslogin(env)
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        r=requests.get(url,headers=header)
        print('数据接入-页面详情')
        return r.json()


    def editElement(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/dict/editElement"
        token = cmslogin(env)
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        data={"id":279,"name":"元素2","elementName":"元素2"}
        r=requests.post(url,data=json.dumps(data),headers=header)
        print('编辑元素名称',r.json())
        return r.json()

    def editElement_null(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/dict/editElement"
        token = cmslogin(env)
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        data={"id":291,"name":"","elementName":""}
        r=requests.post(url,data=json.dumps(data),headers=header)
        print('编辑元素名称为空',r.json())
        return r.json()

    def getAppList(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/dict/getAppList"
        token = cmslogin(env)
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        r=requests.get(url,headers=header)
        print('数据接入-新增-应用列表',r.json())
        return r.json()

    def saveProject(self,env):
        base_url = getconf(env, "data_url1")
        url = base_url + "easydata-web/v1/dict/saveProject"
        token = cmslogin(env)
        header={"Content-Type": "application/json;charset=UTF-8","token":token}
        data={"appName":"商场版定制","appId":"com.rongyi.custom","projectName":"terminal自动化","projectCode":"terminalauto","appType":"1","projectManager":"auto","productManager":"auto1","developer":"auto2","comment":"auto3"}
        r=requests.post(url,data=json.dumps(data),headers=header)
        print('数据接入-新增项目',r.json())
        return r.json()

#b=DataAccess()
#b.getAppSelect('test')